
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef _PWM_H_
#define _PWM_H_

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "stm32f10x_it.h"
#define OUT_FREQ   (1000)
#define PWM_PERIOD (SystemCoreClock / 5000 - 1)

#define DAC1_TIM                 TIM2
#define DAC1_TIM_CLK             RCC_APB1Periph_TIM2
#define DAC1_TIM_CLK_INIT        RCC_APB1PeriphClockCmd
#define DAC1_GPIO_PIN            GPIO_Pin_0
#define DAC1_GPIO_PORT           GPIOA
#define DAC1_GPIO_CLK            RCC_APB2Periph_GPIOA
#define DAC1_TIM_OCInit          TIM_OC1Init
#define DAC1_TIM_OCPreloadConfig TIM_OC1PreloadConfig

#define DAC2_TIM                 TIM2
#define DAC2_TIM_CLK             RCC_APB1Periph_TIM2
#define DAC2_TIM_CLK_INIT        RCC_APB1PeriphClockCmd
#define DAC2_GPIO_PIN            GPIO_Pin_1
#define DAC2_GPIO_PORT           GPIOA
#define DAC2_GPIO_CLK            RCC_APB2Periph_GPIOA
#define DAC2_TIM_OCInit          TIM_OC2Init
#define DAC2_TIM_OCPreloadConfig TIM_OC2PreloadConfig

#define DAC3_TIM                 TIM2
#define DAC3_TIM_CLK             RCC_APB1Periph_TIM2
#define DAC3_TIM_CLK_INIT        RCC_APB1PeriphClockCmd
#define DAC3_GPIO_PIN            GPIO_Pin_2
#define DAC3_GPIO_PORT           GPIOA
#define DAC3_GPIO_CLK            RCC_APB2Periph_GPIOA
#define DAC3_TIM_OCInit          TIM_OC3Init
#define DAC3_TIM_OCPreloadConfig TIM_OC3PreloadConfig

#define DAC4_TIM                 TIM2
#define DAC4_TIM_CLK             RCC_APB1Periph_TIM2
#define DAC4_TIM_CLK_INIT        RCC_APB1PeriphClockCmd
#define DAC4_GPIO_PIN            GPIO_Pin_3
#define DAC4_GPIO_PORT           GPIOA
#define DAC4_GPIO_CLK            RCC_APB2Periph_GPIOA
#define DAC4_TIM_OCInit          TIM_OC4Init
#define DAC4_TIM_OCPreloadConfig TIM_OC4PreloadConfig

#define DAC5_TIM                 TIM3
#define DAC5_TIM_CLK             RCC_APB1Periph_TIM3
#define DAC5_TIM_CLK_INIT        RCC_APB1PeriphClockCmd
#define DAC5_GPIO_PIN            GPIO_Pin_0
#define DAC5_GPIO_PORT           GPIOB
#define DAC5_GPIO_CLK            RCC_APB2Periph_GPIOB
#define DAC5_TIM_OCInit          TIM_OC3Init
#define DAC5_TIM_OCPreloadConfig TIM_OC3PreloadConfig

#define DAC6_TIM                 TIM3
#define DAC6_TIM_CLK             RCC_APB1Periph_TIM3
#define DAC6_TIM_CLK_INIT        RCC_APB1PeriphClockCmd
#define DAC6_GPIO_PIN            GPIO_Pin_1
#define DAC6_GPIO_PORT           GPIOB
#define DAC6_GPIO_CLK            RCC_APB2Periph_GPIOB
#define DAC6_TIM_OCInit          TIM_OC4Init
#define DAC6_TIM_OCPreloadConfig TIM_OC4PreloadConfig

typedef enum {
    PWM_CHANNEL_1 = 0,
    PWM_CHANNEL_2,
    PWM_CHANNEL_3,
    PWM_CHANNEL_4,
    PWM_CHANNEL_5,
    PWM_CHANNEL_6,
    PWM_CHANNEL_MAX,
} PWM_Channel_TypeDef;

void PWM_Init(void);
// void PWM_Out(u16* pwm_value);
void PWM_Out(u16* pwm_value, u8 i);
void PWM1_Set(u16 percent_10);
void PWM2_Set(u16 percent_10);
void PWM3_Set(u16 percent_10);
void PWM4_Set(u16 percent_10);
void PWM5_Set(u16 percent_10);
void PWM6_Set(u16 percent_10);
void PWM_SetDuty(u16 channel, u8 duty);
#ifdef __cplusplus
}
#endif

#endif /* _PWM_H_ */
